import dataList from '@/components/dataList'
import {fetchList} from "../../api/finance-bill-flow";
import receiptData from '../../collection/paid/components/receipt-data'
import {getNewObj} from '../../api/finance-collection-actual'
export default {
    components: {dataList,receiptData},
    provide() {
        return {
            initList: this.getListData,
        };
    },
    beforeMount() {
        this.getListData();
    },
    data() {
        return {
            tableData: [],
            // 请求参数
            params: {
                current: 1,
                size: 20,
                propertyName: ''
            },
            // 分页
            pager: {
                total: 0, // 总页数
                current: 1, // 当前页数
                size: 20 // 每页显示多少条
            },
            // 页面loading
            loading: false,
            filterList: [
                { label: '费用周期', inputType: 'date', name: 'costPeriodStart'},
                { label: '收款日期', inputType: 'date', name: 'collectionDate'}
            ]
        }
    },
    methods: {
        getListData(params = {}) {
            this.loading = true
            let requestData = {...this.params, ...params}
            fetchList(requestData).then(res => {
                const  {current, size, total, records} = res.data.data
                this.tableData = records
                this.params = requestData
                this.pager = {total, current, size}
            }).finally(() => {
                this.loading = false
            })
        },
        receipt(item) {
            getNewObj(item.actualId).then(respData => {
                if (respData.data.data) {
                    this.$refs.receiptData.show(respData.data.data)
                } else {
                    this.$message.error('暂无数据，无法查看！')
                }
            })
        },
    },
    watch:{
        tableData(){
            for(let i=0;i<this.tableData.length;i++){
                this.tableData[i].costPeriodStart=this.tableData[i].costPeriodStart+'——'+this.tableData[i].costPeriodEnd
            }
        }
    }
}
